<?php

    class RatePlan
    {
        const TYPE_CUSTOM = "custom";

        /**
         * @var string
         */
        public $key;

        /**
         * @var string
         */
        public $title;

        /**
         * @var string
         */
        public $type;

        /**
         * @var int
         */
        public $maxUser;

        /**
         * @var string
         */
        public $maxSupervisors;

        /**
         * @var string
         */
        public $maxPublishers;
        /**
         * @var string
         */
        public $maxJointLicenses;

        /**
         * @var string
         */
        public $maxContentItems;

        /**
         * @var array
         */
        public $cost;

        /**
         * @var array
         */
        public $save;

        /**
         * @var array
         */
        public $productBundlePrice;

        /**
         * @var array
         */
        public $productBundleSave;

        public function Parse( XPathHelper $helper )
        {
            $this->key              = $helper->GetText("Key");
            $this->title            = $helper->GetText("Title");
            $this->type             = $helper->GetText("Type");
            $this->maxUser          = intval($helper->GetText("MaxUsers"));
            $this->maxSupervisors   = intval($helper->GetText("MaxSupervisors"));
            $this->maxSupervisors   = ( $this->maxSupervisors > 0 ) ? $this->maxSupervisors : "Unlimited";
            $this->maxPublishers    = intval($helper->GetText("MaxPublishers"));
            $this->maxPublishers    = ( $this->maxPublishers > 0 ) ? $this->maxPublishers : "Unlimited";
            $this->maxJointLicenses = intval( $helper->GetText("MaxJointLicenses") );
            $this->maxContentItems  = intval($helper->GetText("MaxContentItems"));
            $this->maxContentItems  = ( $this->maxContentItems > 0 ) ? $this->maxContentItems : "Unlimited";
        }

        public function GetCost( $period, $isBundlePrice = false )
        {
            return $isBundlePrice ? $this->productBundlePrice[$period] : $this->cost[$period];
        }

        public function IsCustom()
        {
            return $this->type == "custom";
        }
    }

?>
